export class SpeedDistanceTime {
    // 距离=速度x时间
    public static toDistance(speed: number, time: number): number {
        return speed * time;
    }
    // 时间=距离/速度
    public static toTime(speed: number, distance: number): number {
        return divide(distance, speed);
    }

    // 速度=距离/时间
    public static toSpeed(time: number, distance: number): number {
        return divide(distance, time);
    }
}

// 安全除法,可以除0
export function divide(a: number, b: number) {
    if (b == 0) {
        return 0;
    }
    return a / b;
}

//线性移动
export function Linear(
    start: number,
    end: number,
    time: number,
    duration: number,
    easing: (number: number) => number,
) {
    const t = easing(divide(time, duration));
    return start + (end - start) * t;
}

export function clamp(val: number, min: number, max: number) {
    if (val < min) {
        return min;
    }
    if (val > max) {
        return max;
    }
    return val;
}
